package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.DataResult;
import com.company.project.common.utils.Func;
import com.company.project.entity.CallbackEntityVo1;
import com.company.project.entity.CallbackEntityVo2;
import com.company.project.entity.TWdkhEntity;
import com.company.project.entity.TWdkhUploadEntity;
import com.company.project.service.TGhkhService;
import com.company.project.service.TSeatsService;
import com.company.project.service.TWdkhService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-11-09 18:03:05
 */
@RestController
@RequestMapping("/")
public class TWdkhUploadController {
    @Autowired
    private TWdkhService tWdkhService;
    @Autowired
    private TGhkhService ghkhService;
    @Autowired
    private TSeatsService tSeatsService;
    @PostMapping("index/callbak/dxline")
    @LogAnnotation(title = "外呼回到", action = "外呼回到 dxline")
    public DataResult notifyurl(@RequestBody CallbackEntityVo1 vo) {
        tSeatsService.notifyurl1(vo);
        return DataResult.success();
    }

    @PostMapping("index/callbak/dyline")
    @LogAnnotation(title = "外呼回到", action = "外呼回到 dyline")
    public DataResult dyline(@RequestBody CallbackEntityVo2 vo) {
        tSeatsService.dyline(vo);
        return DataResult.success("",0000);
    }

    @PostMapping("index/callbak/llline")
    @LogAnnotation(title = "外呼回到", action = "外呼回到 llline")
    public DataResult llline(@RequestBody Map<String, Object> vo) {
        tSeatsService.llline(vo);
        return DataResult.success("",0000);
    }
    @ApiOperation(value = "我的客户 导入新增")
    @LogAnnotation(title = "我的客户", action = "我的客户 导入新增")
    @PostMapping("wd/tWdkh/upload")
    public DataResult upload(@RequestParam(value = "file") MultipartFile file) {
        //判断文件是否空
        if (file == null || file.getOriginalFilename() == null || "".equalsIgnoreCase(file.getOriginalFilename().trim())) {
            return DataResult.fail("文件为空");
        }
        String name = file.getOriginalFilename();
        String suffix = name.substring(name.lastIndexOf('.'));
        if(!suffix.equals(".xls")){
            return DataResult.fail("上传文件不是excel,正确文件后缀‘.xls’！");
        }
        return tWdkhService.saveFile(file);
    }
    @ApiOperation(value = "公海客户 导入新增")
    @LogAnnotation(title = "公海客户", action = "公海客户 导入新增")
    @PostMapping("wd/tGhkh/upload")
    public DataResult ghkhUpload(TWdkhUploadEntity upload) {
        MultipartFile file = upload.getFile();
        String id = upload.getId();
        //判断文件是否空
        if (file == null || file.getOriginalFilename() == null || "".equalsIgnoreCase(file.getOriginalFilename().trim())) {
            return DataResult.fail("文件为空");
        }
        String name = file.getOriginalFilename();
        String suffix = name.substring(name.lastIndexOf('.'));
        if(!suffix.equals(".xls")){
            return DataResult.fail("上传文件不是excel,正确文件后缀‘.xls’！");
        }
        return ghkhService.saveFile(file,id);
    }
}
